version 14.1
set more off

***************************************************************************************************
*THIS FILE PRODUCES TABLE A.VI OF SLEMROD-REHMAN-WASEEM-2020, RESTAT
***************************************************************************************************

/* PRELIMINARIES */

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed.dta", clear
#d					;
matrix 			input table=(0,0,0,0\0,0,0,0\0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\0,0,0,0\0,0,0,0);
#d					cr

/* DEFINE TREATMENT VARIABLE */

g					logtaxpaid=log(TaxPaid)
bys				regno:egen namefreq=min(name_count_v2)
g					after=year>=2012
local				i=1
forvalues		n=50(50)450 {
local				nl=`n'-50
g					treat`i'=(namefreq>`nl' & namefreq<=`n')
g					treat_after`i'=treat`i'*after
local				i=`i'+1
}

/* COLUMN 1 (BASELINE) */

qui				areg logtaxpaid i.year treat_after*, absorb(regno) cluster(regno)
local				i=1
local				j=1
forvalues		k=1/9 {
matrix			table[`i',`j']=_b[treat_after`k']
matrix 			table[`i'+1,`j']=_se[treat_after`k']
local				i=`i'+2
}
matrix			table[19,`j']=e(N)
local				j=`j'+1

/* COLUMN 2 (BALANCE PANEL) */

bys				regno:g nreturns=_N
keep				if nreturns==10
qui				areg logtaxpaid i.year treat_after*, absorb(regno) cluster(regno)
local				i=1
forvalues		k=1/9 {
matrix			table[`i',`j']=_b[treat_after`k']
matrix 			table[`i'+1,`j']=_se[treat_after`k']
local				i=`i'+2
}
matrix			table[19,`j']=e(N)
local				j=`j'+1

*--------------------------------
* PLACEBO REGRESSION 
*--------------------------------

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed.dta", clear
g					logtaxpaid=log(TaxPaid)
bys				regno:egen namefreq=min(name_count_v2)
drop				if year>=2012
g					after=year>=2010
local				i=1
forvalues		n=50(50)450 {
local				nl=`n'-50
g					treat`i'=(namefreq>`nl' & namefreq<=`n')
g					treat_after`i'=treat`i'*after
local				i=`i'+1
}

/* COLUMN 1 (BASELINE) */

qui				areg logtaxpaid i.year treat_after*, absorb(regno) cluster(regno)
local				i=1
forvalues		k=1/9 {
matrix			table[`i',`j']=_b[treat_after`k']
matrix 			table[`i'+1,`j']=_se[treat_after`k']
local				i=`i'+2
}
matrix			table[19,`j']=e(N)
local				j=`j'+1

/* COLUMN 2 (BALANCE PANEL) */

bys				regno:g nreturns=_N
keep				if nreturns==6
qui				areg logtaxpaid i.year treat_after*, absorb(regno) cluster(regno)
local				i=1
forvalues		k=1/9 {
matrix			table[`i',`j']=_b[treat_after`k']
matrix 			table[`i'+1,`j']=_se[treat_after`k']
local				i=`i'+2
}
matrix			table[19,`j']=e(N)
local				j=`j'+1

/* FORMATTING THE TABLE */

svmat 			table
keep				tab*
keep				if _n<=19
g					c11=""
replace			c11="Name Freq $\in (0,\;50]\; \times$ after" in 1
replace			c11="Name Freq $\in (50,\;100]\; \times$ after" in 3
replace			c11="Name Freq $\in (100,\;150]\; \times$ after" in 5
replace			c11="Name Freq $\in (150,\;200]\; \times$ after" in 7
replace			c11="Name Freq $\in (200,\;250]\; \times$ after" in 9
replace			c11="Name Freq $\in (250,\;300]\; \times$ after" in 11
replace			c11="Name Freq $\in (300,\;350]\; \times$ after" in 13
replace			c11="Name Freq $\in (350,\;400]\; \times$ after" in 15
replace			c11="Name Freq $\in (400,\;450]\; \times$ after" in 17
replace			c11="Observations" in 19

forvalues 		c=1/4 {
g					c`c'=string(table`c',"%9.3f")
}
forvalues		r=2(2)18 {
forvalues		c=1/4 {
replace			c`c'="("+string(table`c',"%9.3f")+")" in `r'
}
}
forvalues		c=1/4 {
replace			c`c'=string(table`c',"%15.0fc") in 19
}
forvalues		s=1/10 {
g					s`s'="&"
}
g					l="\\"
foreach			r in 18 19 {
replace			l="\\\\" in `r'
}
order				c11 s1 c1 s2 s3 c2 s4 s5 c3 s6 s7 c4 l
browse			c11 s1 c1 s2 s3 c2 s4 s5 c3 s6 s7 c4 l
